import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: '首页',
        icon: 'dashboard'
      }
    }]
  },
  {
    path: '/warning-reminder',
    component: Layout,
    children: [{
      path: 'index',
      name: '告警提醒',
      component: () => import('@/views/warning-reminder/index'),
      meta: {
        title: '告警提醒',
        icon: 'form'
      }
    }]
  },
  {
    path: '/project',
    component: Layout,
    children: [{
      path: 'index',
      name: '项目管理',
      component: () => import('@/views/project/index'),
      meta: {
        title: '项目管理',
        icon: 'example'
      }
    }]
  },
  {
    path: '/control-source',
    component: Layout,
    children: [{
      path: 'index',
      name: '监控源管理',
      component: () => import('@/views/control-source/index'),
      meta: {
        title: '监控源管理',
        icon: 'form'
      }
    }]
  },
  {
    path: '',
    component: Layout,
    meta: {
      title: '业务流程',
      icon: 'form'
    },
    children: [{
        path: '/logs',
        component: () => import('@/views/logs/index'),
        name: '异常',
        meta: {
          title: '业务流程异常',
          icon: 'form'
        }
      },
      {
        path: '/hading_result',
        name: '业务流程异常处理结果',
        component: () => import('@/views/handing_result/index'),
        meta: {
          title: '异常处理结果',
          icon: 'form'
        }
      }
    ]
  },
  {
    path: '/timing_rule',
    component: Layout,
    children: [{
      path: 'index',
      name: '定时规则记录',
      component: () => import('@/views/timing_rule/index'),
      meta: {
        title: '定时规则记录',
        icon: 'form'
      }
    }]
  },
  // {
  //   path: '',
  //   component: Layout,
  //   meta: {title: '规则运行', icon: 'form'},
  //   children: [
  //     {
  //       path: '/logs',
  //       component: () => import('@/views/logs/index'),
  //       name: '异常',
  //       meta: {title: '业务流程异常', icon: 'form'}
  //     },
  //     {
  //       path: '/hading_result',
  //       name: '业务流程异常处理结果',
  //       component: () => import('@/views/handing_result/index'),
  //       meta: { title: '异常处理结果', icon: 'form' }
  //     }
  //   ]
  // },
  {
    path: '/console_error',
    component: Layout,
    meta: {
      title: '规则运行',
      icon: 'form'
    },
    children: [{
        path: 'index',
        name: '规则运行异常',
        component: () => import('@/views/console_error/index'),
        meta: {
          title: '规则运行异常',
          icon: 'form'
        }
      },
      {
        path: '/hading',
        name: '业务流程异常处理结果',
        component: () => import('@/views/console_error/hading'),
        meta: {
          title: '异常处理结果',
          icon: 'form'
        }
      }
    ]
  },
  {
    path: '/datasource_monitor',
    component: Layout,
    children: [{
      path: 'index',
      name: '连接池监控',
      component: () => import('@/views/datasource_monitor/index'),
      meta: {
        title: '连接池监控',
        icon: 'form'
      }
    }]
  },
  {
    path: '/systemtask',
    component: Layout,
    children: [{
      path: 'index',
      name: '系统监控任务',
      component: () => import('@/views/systemtask/index'),
      meta: {
        title: '系统监控任务',
        icon: 'form'
      }
    }]
  },
  /*  {
      path: '/set',
      name: '后台配置',
      meta: { title: '后台配置', icon: 'form' },
      component: Layout,
      children: [{
        path: 'dept',
        name: '组织管理',
        component: () => import('@/views/system/dept/index'),
        meta: { title: '组织管理', icon: 'form' }
      },{
        path: 'role',
        name: '角色管理',
        component: () => import('@/views/system/role/index'),
        meta: { title: '角色管理', icon: 'form' }
      }]
    },*/
  {
    path: '/form',
    component: Layout,
    /* children: [
       {
         path: 'index',
         name: 'Form',
         component: () => import('@/views/form/index'),
         meta: { title: 'Form', icon: 'form' }
       }
     ]*/
  },
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
